<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row class="form-row" :gutter="24">
          <a-col :lg="12">
            <a-form-item label="创建人名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'createName', validatorRules.createName]" placeholder="请输入创建人名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="创建人登录名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'createBy', validatorRules.createBy]" placeholder="请输入创建人登录名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="创建日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择创建日期" v-decorator="[ 'createTime', validatorRules.createTime]" :trigger-change="true" style="width: 100%"/>
            </a-form-item>  
          </a-col>
          <a-col :lg="12">
            <a-form-item label="更新人名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'updateName', validatorRules.updateName]" placeholder="请输入更新人名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="更新人登录名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'updateBy', validatorRules.updateBy]" placeholder="请输入更新人登录名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="更新日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择更新日期" v-decorator="[ 'updateTime', validatorRules.updateTime]" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="所属部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'sysOrgCode', validatorRules.sysOrgCode]" placeholder="请输入所属部门"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="所属公司" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'sysCompanyCode', validatorRules.sysCompanyCode]" placeholder="请输入所属公司"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="流程状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'bpmStatus', validatorRules.bpmStatus]" placeholder="请输入流程状态"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="前端编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'appCode', validatorRules.appCode]" placeholder="请输入前端编码"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'appRemark', validatorRules.appRemark]" placeholder="请输入备注"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="appID" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'appId', validatorRules.appId]" placeholder="请输入appID"></a-input>
              <!-- <a-textarea v-decorator="['appId', validatorRules.appId]" rows="4" placeholder="请输入appID"/> -->
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="appsecret" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'appSecret', validatorRules.appSecret]" placeholder="请输入appsecret"></a-input>
              <!-- <a-textarea v-decorator="['appSecret', validatorRules.appSecret]" rows="4" placeholder="请输入appsecret"/> -->
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="appkey" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'appKey', validatorRules.appKey]" placeholder="请输入appkey"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="商户号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'mchId', validatorRules.mchId]" placeholder="请输入商户号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="通知地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'notifyUrl', validatorRules.notifyUrl]" placeholder="请输入通知地址"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="GRANT_TYPE" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'grantType', validatorRules.grantType]" placeholder="请输入GRANT_TYPE"></a-input>
              <!-- <a-textarea v-decorator="['grantType', validatorRules.grantType]" rows="4" placeholder="请输入GRANT_TYPE"/> -->
            </a-form-item>  
          </a-col>
          <a-col :lg="12">
            <a-form-item label="备用1" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'wxBy1', validatorRules.wxBy1]" placeholder="请输入备用1"></a-input>
              <!-- <a-textarea v-decorator="['wxBy1', validatorRules.wxBy1]" rows="4" placeholder="请输入备用1"/> -->
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="备用2" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'wxBy2', validatorRules.wxBy2]" placeholder="请输入备用2"></a-input>
              <!-- <a-textarea v-decorator="['wxBy2', validatorRules.wxBy2]" rows="4" placeholder="请输入备用2"/> -->
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="备用3" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'wxBy3', validatorRules.wxBy3]" placeholder="请输入备用3"></a-input>
              <!-- <a-textarea v-decorator="['wxBy3', validatorRules.wxBy3]" rows="4" placeholder="请输入备用3"/> -->
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="备用4" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'wxBy4', validatorRules.wxBy4]" placeholder="请输入备用4"></a-input>
              <!-- <a-textarea v-decorator="['wxBy4', validatorRules.wxBy4]" rows="4" placeholder="请输入备用4"/> -->
            </a-form-item>
          </a-col>
          <a-col :lg="12">
            <a-form-item label="备用5" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="[ 'wxBy5', validatorRules.wxBy5]" placeholder="请输入备用5"></a-input>
              <!-- <a-textarea v-decorator="['wxBy5', validatorRules.wxBy5]" rows="4" placeholder="请输入备用5"/> -->
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  

  export default {
    name: "WxConfigEntityModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:1200,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          createName: {rules: [
          ]},
          createBy: {rules: [
          ]},
          createTime: {rules: [
          ]},
          updateName: {rules: [
          ]},
          updateBy: {rules: [
          ]},
          updateTime: {rules: [
          ]},
          sysOrgCode: {rules: [
          ]},
          sysCompanyCode: {rules: [
          ]},
          bpmStatus: {rules: [
          ]},
          appCode: {rules: [
          ]},
          appRemark: {rules: [
          ]},
          appId: {rules: [
          ]},
          appSecret: {rules: [
          ]},
          appKey: {rules: [
          ]},
          mchId: {rules: [
          ]},
          notifyUrl: {rules: [
          ]},
          grantType: {rules: [
          ]},
          wxBy1: {rules: [
          ]},
          wxBy2: {rules: [
          ]},
          wxBy3: {rules: [
          ]},
          wxBy4: {rules: [
          ]},
          wxBy5: {rules: [
          ]},
        },
        url: {
          add: "/base/wxConfigEntity/add",
          edit: "/base/wxConfigEntity/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createName','createBy','createTime','updateName','updateBy','updateTime','sysOrgCode','sysCompanyCode','bpmStatus','appCode','appRemark','appId','appSecret','appKey','mchId','notifyUrl','grantType','wxBy1','wxBy2','wxBy3','wxBy4','wxBy5'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createName','createBy','createTime','updateName','updateBy','updateTime','sysOrgCode','sysCompanyCode','bpmStatus','appCode','appRemark','appId','appSecret','appKey','mchId','notifyUrl','grantType','wxBy1','wxBy2','wxBy3','wxBy4','wxBy5'))
      },

      
    }
  }
</script>